<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/css/swiper.css">
</head>
<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/js/swiper.js"></script>
  <script>
    const Home = {
      template: `
        <div>
          <h2>home组件</h2>
          <button @click="addLi">增加li</button>  
          <ul ref="oul">
            <li v-for="item in arr" :key="item">
              {{ item }}  
            </li>  
          </ul>
        </div>
      `,
      methods: {
        addLi(){
          this.arr.push(this.arr.length+1);
        }
      },
      data(){
        return {
          msg: '你好世界',
          arr: [1,2,3,4]
        }
      },
      mounted(){
        console.log('template已经编译完成--mounted');
      },
      beforeUpdate(){
        console.log('视图更新之前--beforeUpdate');
        
        
      },
      updated(){
        console.log('视图已经更新完成--updated');
        const oul = this.$refs.oul;
        oul.lastElementChild.style.background = 'red';
      }
    }
    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>